// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   IRSensorView.java

package jones.gui;

import java.awt.*;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import jones.SimpleRobot;

public class IRSensorView extends JPanel
    implements Observer
{
    private class SingleIRSensorView extends JPanel
    {

        private boolean isOn = false;

        public void setIsOn(boolean isOn)
        {
            this.isOn = isOn;
        }

        public void paintComponent(Graphics g)
        {
            super.paintComponent(g);
            if (isOn)
            {
                g.setColor(Color.red);
                g.fillOval(0, 0, getWidth(), getHeight());
            }
            g.setColor(Color.black);
            g.drawOval(0, 0, getWidth() - 1, getHeight() - 1);
        }

        public SingleIRSensorView()
        {
            isOn = false;
            setPreferredSize(new Dimension(30, 30));
        }
    }


    private SingleIRSensorView leftView = null;
    private SingleIRSensorView rightView = null;

    public IRSensorView()
    {
        leftView = new SingleIRSensorView();
        rightView = new SingleIRSensorView();
        add(((java.awt.Component) (leftView)));
        add(((java.awt.Component) (rightView)));
    }

    public void update(Observable obs, Object obj)
    {
        final SimpleRobot robot = (SimpleRobot)obs;
        SwingUtilities.invokeLater(new Runnable() {

            public void run()
            {
                leftView.setIsOn(robot.isLeftIROn());
                rightView.setIsOn(robot.isRightIROn());
            }

        }
);
        repaint();
    }


}
